package com.ljq.software_springboot.softwareprogram.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ljq.software_springboot.softwareprogram.entity.Account;
import com.ljq.software_springboot.softwareprogram.entity.ChatMessage;
import com.ljq.software_springboot.softwareprogram.imp.ChatMessageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-29
 */
@RestController
@RequestMapping("/chat-message")
@CrossOrigin(origins = "http://localhost:5173")
public class ChatMessageController {
    @Autowired
    private ChatMessageServiceImpl messageService;

    @PostMapping("/send")
    public Boolean sendMessage(@RequestBody ChatMessage message) {
        messageService.saveMessage(message);  // 保存消息到数据库
        return true;
    }
    // 获取聊天消息历史
    @PostMapping("/messages")
    public List<ChatMessage> getMessages(@RequestBody ChatMessage message) {
        List<ChatMessage> chatMessages = messageService.getMessages(message.getSenderId(), message.getRecipientId());
        return chatMessages;
    }
}
